import Vue from 'vue';

import Router from 'vue-router'
import App from './App.vue'

Vue.use(Router);

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'app',
      redirect: '/home',
      component: App,
      children: [
        {
          path: 'home',
          name: 'home',
          redirect: 'home/user',
          component: () => import('./views/Header'),
          children: [
            {
              path: 'user',
              name: 'user',
              redirect: 'user/nav-module/1',
              component: () => import('./views/sidebar/User'),
              children: [
                {
                  path: 'nav-module/:id',
                  name: 'nav-module',
                  meta: {
                    title: 'U教云'
                  },
                  component: () => import('./views/NavModule')
                }
              ]
            },
            {
              path: 'module',
              name: 'module',
              component: () => import('./views/sidebar/Module'),
              children: [
                {
                  path: 'receipt',
                  name: 'receipt',
                  meta: {
                    title: '内部通知-收件箱',
                    roles: ['module']
                  },
                  component: () => import('./views/modules/message/Receipt') // 模块
                },
                {
                  path: 'outbox',
                  name: 'outbox',
                  meta: {
                    title: '内部通知-发件箱',
                    roles: ['module']
                  },
                  component: () => import('./views/modules/message/Outbox') // 模块
                },
                {
                  path: 'manage',
                  name: 'manage',
                  meta: {
                    title: '内部通知-管理配置',
                    roles: ['module']
                  },
                  component: () => import('./views/modules/message/Manage') // 模块
                },
                {
                  path: 'module-manage',
                  name: 'module-manage',
                  meta: {
                    title: '管理配置',
                    roles: ['module']
                  },
                  component: () => import('./views/modules/moduleManage/Index') // 模块
                },
                {
                  path: 'visitor',
                  name: 'visitor',
                  redirect: 'visitor/Visitor',
                  component: () => import('./views/modules/visitor/App'),
                  children: [
                    {
                      path: 'Visitor',
                      name: 'Visitor',
                      meta: {
                        title: '我的访客',
                        roles: ['module']
                      },
                      component: () => import('./views/modules/visitor/Visitor.vue') // 访客-我的访客
                    },
                    {
                      path: 'VisitorAll',
                      name: 'VisitorAll',
                      meta: {
                        title: '查看全部',
                        roles: ['module']
                      },
                      component: () => import('./views/modules/visitor/VisitorAll.vue') // 访客-查看全部
                    }
                  ]

                },

                {
                  path: 'schedule',
                  name: 'schedule',
                  meta: {
                    title: '日程',
                    roles: ['module']
                  },
                  component: () => import('./views/modules/schedule/Schedule') // 日程模块
                },
                {
                  path: 'screen-manage',
                  name: 'screen-manage',
                  redirect: 'screen-manage/custom-screen',
                  meta: {
                    title: '云屏管理'
                  },
                  component: () => import('./views/modules/screenManage/App'), // 云屏管理模块
                  children: [
                    {
                      path: 'custom-screen',
                      name: 'CustomScreen',
                      meta: {
                        title: '云屏自定义'
                      },
                      component: () => import('./views/modules/screenManage/CustomScreen') // 云屏自定义
                    },
                    {
                      path: 'custom-screen1',
                      name: 'CustomScreen1',
                      meta: {
                        title: '云屏自定义1'
                      },
                      component: () => import('./views/modules/screenManage/CustomScreen1') // 云屏自定义
                    }
                  ]
                },
                { // 会议
                  path: 'meeting',
                  name: 'meeting',
                  redirect: 'meeting/initiate',
                  component: () => import('./views/modules/meeting/App'),
                  children: [
                    {
                      path: 'initiate',
                      name: 'initiate',
                      meta: {
                        title: '我参与的会议'
                      },
                      component: () => import('./views/modules/meeting/InitiateMeeting') // 我参与的会议
                    },
                    {
                      path: 'partake',
                      name: 'partake',
                      meta: {
                        title: '发起会议'
                      },
                      component: () => import('./views/modules/meeting/PartakeMeeting') // 我发起的会议
                    },
                    {
                      path: 'all',
                      name: 'all',
                      meta: {
                        title: '全部会议'
                      },
                      component: () => import('./views/modules/meeting/AllMeeting') // 全部会议
                    },
                    {
                      path: 'add/:id',
                      name: 'add',
                      meta: {
                        title: '新增会议'
                      },
                      component: () => import('./views/modules/meeting/AddMeeting') // 新增会议
                    },
                    {
                      path: 'detail',
                      name: 'detail',
                      meta: {
                        title: '会议详情'
                      },
                      component: () => import('./views/modules/meeting/DetailMeeting') // 会议详情
                    }
                  ]
                },
                {
                  path: 'not-auth',
                  name: 'NotAuth',
                  meta: {
                    title: 'U教云|404'
                  },
                  component: () => import('_views/NotAuth') // 无权限页面
                }
              ]
            }
          ]
        }
      ]
    }
  ]
});
router.beforeEach((to, from, next) => {
  // 修改title
  document.title = to.meta.title;
  // 获取当前登陆账号的身份
  const UserRoles = JSON.parse(localStorage.getItem('roles'));
  if (to.meta.roles && !UserRoles.includes(to.meta.roles)) {
    router.push('/home/module/not-auth')
  }
  next();
});
export default router
